package LeetCode.leetcode112;

public class Review1 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) return false;
        return backTracking(root, targetSum, 0);
    }

    public static boolean backTracking(TreeNode node, int target, int sum) {
        sum += node.val;
        if (node.left == null && node.right == null) {
            return target == sum;
        }
        if (node.left != null) {
            boolean l = backTracking(node.left, target, sum);
            if (l) return true;
        }
        if (node.right != null) {
            boolean r = backTracking(node.right, target, sum);
            if (r) return true;
        }
        return false;
    }
}
